//
//  DDSearchController.m
//  DingDongZP
//
//  Created by Jyh on 16/4/5.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDSearchController.h"

@interface DDSearchController () <UITextFieldDelegate, UITableViewDelegate, UITableViewDataSource>

@end

@implementation DDSearchController

#pragma mark
#pragma mark - View LifeCycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self setupData];
    [self setupView];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark
#pragma mark - Private Methods

- (void)setupData
{
    
}

- (void)setupView
{
//    WEAKSELF
    [self.view addSubview:self.navigationView];
    [self.navigationView addSubview:self.textField];
    [self.navigationView addSubview:self.cancleButton];
    
//    self.tableView.frame = CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64);
//    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.center.equalTo(weakSelf.view);
//        make.edges.mas_offset(UIEdgeInsetsMake(64, 0, 0, 0));
//    }];
}


#pragma mark
#pragma mark - Event Response

- (void)cancleButtonClick:(UIButton *)button
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark
#pragma mark - CustomDelegate

#pragma mark - UITableView DataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"cellIdentfier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
        
    }
    
    cell.textLabel.text = @"搜索结果";
    
    return cell;
}


#pragma mark
#pragma mark - Getters and Setters

- (UISearchBar *)searchBar
{
    if (_searchBar == nil) {
        _searchBar = [[UISearchBar alloc] init];
    }
    return _searchBar;
}

- (UIView *)navigationView
{
    if (_navigationView == nil) {
        _navigationView = [[UIView alloc] init];
        _navigationView.backgroundColor = COLOR_NAVIGATIONBAR;
        _navigationView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 64);
    }
    return _navigationView;
}

- (UITextField *)textField
{
    if (_textField == nil) {
        _textField = [[UITextField alloc] init];
        _textField.placeholder = @"输入您擅长的技能";
        _textField.frame = CGRectMake(10, 25, SCREEN_WIDTH - 100, 29);
        _textField.backgroundColor = [UIColor colorWithWhite:1 alpha:0.5];
        _textField.textColor = [UIColor whiteColor];
        _textField.clearButtonMode = UITextFieldViewModeWhileEditing;
        _textField.layer.cornerRadius = 14;
        _textField.layer.masksToBounds = YES;
    }
    
    return _textField;
}

- (UIButton *)cancleButton
{
    if (_cancleButton == nil) {
        _cancleButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_cancleButton setTitle:@"取消" forState:UIControlStateNormal];
        [_cancleButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_cancleButton addTarget:self action:@selector(cancleButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        _cancleButton.frame = CGRectMake(SCREEN_WIDTH - 80, 25, 60, 30);
    }
    
    return _cancleButton;
}

- (UITableView *)tableView
{
    if (_tableView == nil) {
        CGRect tableViewFrame = self.view.bounds;
        tableViewFrame.origin.y = 64;
        tableViewFrame.size.height -= 64;
        
        _tableView = [[UITableView alloc] initWithFrame:tableViewFrame style:UITableViewStyleGrouped];
        
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.backgroundColor = COLOR_BACKGROUND;
    }
    
    return _tableView;
}

@end
